package com.study.firstline.utils

import java.lang.StringBuilder

/**
 *
 *  @author hexiao
 *  @date  2023/3/10 15:34
 *  @package com.study.firstline.utils
 *  @project FirstLineCodeApp
 *  @desc
 */
class StandardMethodTest {

    /**
     * 返回值
     */
    fun withTest(){
        val list = listOf("Apple", "Banana", "Orange", "Pear", "Grape");
        val s= with(StringBuilder()){
            append("start eating fruits.\n");
            for (s in list) {
                append(s).append("\n");
            }
            toString();
        }
        print("with用法 $s");
    }
    /**
     * 返回值
     */
    fun runTest(){
        val list = listOf("Apple", "Banana", "Orange", "Pear", "Grape");
        val s=StringBuilder().run {
            append("start eating fruits.\n");
            for (s in list) {
                append(s).append("\n");
            }
            toString();
        }
        print("run用法 $s");
    }

    /**
     * 只会返回对象
     */
    fun applyTest(){
        val list = listOf("Apple", "Banana", "Orange", "Pear", "Grape");
        val s=StringBuilder().apply {
            append("start eating fruits.\n");
            for (s in list) {
                append(s).append("\n");
            }
        }
        print("run用法 ${s.toString()}");
    }


}

class Test1{
    companion object{
        @JvmStatic
        fun test(){
            print("伴生类方式。")
        }
    }
}


